package com.company.cloud.goodsrestservice.service.impl;

import com.company.cloud.goodsrestservice.core.AbstractService;
import com.company.cloud.goodsrestservice.dao.OrderMapper;
import com.company.cloud.goodsrestservice.model.Order;
import com.company.cloud.goodsrestservice.service.OrderService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;


/**
 * Created by reabout on 2018/03/24.
 */
@Service
@Transactional
public class OrderServiceImpl extends AbstractService<Order> implements OrderService {
    @Resource
    private OrderMapper goodsOrderMapper;

    public Integer add(Order order) {
        Order o = goodsOrderMapper.selectOne(order);
        if (o == null) {
            Long now = System.currentTimeMillis();
            order.setCreateTime(now);
            order.setUpdateTime(now);
            save(order);
            o = goodsOrderMapper.selectOne(order);
        }

        return o.getOrderId();
    }

    public List<Order> getBy(Order order) {
       List<Order> result = goodsOrderMapper.select(order);
       return result;
    }

}
